const HtmlWebpackPlugin = require('html-webpack-plugin')
const path = require('path')
const { VueLoaderPlugin } = require('vue-loader')

module.exports = {
    entry: './src/index.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.js'
    },
    module: {
        rules: [
            { test: /\.vue$/, use: "vue-loader" },
            { test: /\.js$/, use: 'babel-loader' },
            { test: /\.css/, use: ['vue-style-loader', 'css-loader'] },
            { test: /\.less/, use: ['vue-style-loader', 'css-loader', 'less-loader'] },
            {
                test: /\.(png|jpe?g|gif)$/,
                loader: 'url-loader',
                options: {
                    esModule: false
                }
            },
            { test: /\.html$/, use: 'html-loader' }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: path.join(__dirname, './src/index.html'),
            filename: 'index.html'
        }),
        new VueLoaderPlugin()
    ],
    mode: 'development',
    devServer: {
        static: path.resolve(__dirname, 'src'),
        compress: true,
        port: 9000,
        hot: true,
        open: true,
        proxy: {
            '/api': {
                target: 'http://jsonplaceholder.typicode.com/',
                changeOrigin: true,
                pathRewrite: {
                    '^/api': ''
                }
            },
            '/news': {
                target: 'http://v.juhe.cn/toutiao',
                //appkey: eac50bc36af78dbe3467c8358f259e59
                changeOrigin: true,
                pathRewrite: {
                    '^/news': ''
                }
            }
        }
    },
    resolve: {
        alias: {
            'vue': 'vue/dist/vue.js'
        }
    }

}